package com.qingcheng.controller;

import com.qingcheng.entity.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

//解决异常处理
@ControllerAdvice
public class BaseExceptionHandler {

    @ExceptionHandler(Exception.class)//制定异常类型,可以制定特定的
    @ResponseBody//自动转化成一个json
    public Result error(Exception e) {
        e.printStackTrace();
        System.out.println("调用了异常处理");
        return new Result(1,e.getMessage());
    }
}
